package com.ling.design;

import com.alibaba.fastjson.JSON;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @author: ling007
 * @date: 2024/9/19 15:44
 * @description: 通用MQ消息体
 * 将MQ的不同属性，映射成我们需要的属性
 */

public class MQAdapter {

    public static RebateInfo filter(String strJson, Map<String,String> link) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
        return filter(JSON.parseObject(strJson, Map.class),link);
    }

    public static RebateInfo filter(Map obj, Map<String,String> link) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        RebateInfo rebateInfo = new RebateInfo();
        for (String key : link.keySet()) {
            Object val = obj.get(link.get(key));
            RebateInfo.class.getMethod("set" +
                    key.substring(0, 1).toUpperCase()+key.substring(1), String.class)
                    .invoke(rebateInfo,val.toString());
        }
        return rebateInfo;
    }
}
